﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Data.Odbc;
namespace caculate
{
    public partial class Form2 : Form
    {
        public Form2()
        {
            InitializeComponent();
        }

        private void Form2_Load(object sender, EventArgs e)
        {
           

            string conString = "DSN=test;UID=root;PWD=123456"; //ODBC的数据源名
            OdbcConnection con1 = new OdbcConnection(conString);
            con1.Open();
            OdbcConnection con2 = new OdbcConnection(conString);
            con2.Open();
            OdbcConnection con3 = new OdbcConnection(conString);
            con3.Open();

            string sql2 = "select classID from TeacherMessage where TeacherAccount='" + Form1.PublicValue.prtaccount + "'";
            OdbcCommand com2 = new OdbcCommand(sql2, con2);
            string classID = Convert.ToString(com2.ExecuteScalar());


            string sql1 = "select distinct date from problem where classID='" + classID + "'";
            OdbcCommand com1 = new OdbcCommand(sql1, con1);
            OdbcDataReader sdr1 = com1.ExecuteReader();
            while (sdr1.Read())
            {

                comboBox1.Items.Add(sdr1[0]);

            }
        }

        private void button1_Click(object sender, EventArgs e)
        {
            string conString = "DSN=test;UID=root;PWD=123456"; //ODBC的数据源名
            OdbcConnection con1 = new OdbcConnection(conString);
            con1.Open();
            OdbcConnection con2 = new OdbcConnection(conString);
            con2.Open();
            OdbcConnection con3 = new OdbcConnection(conString);
            con3.Open();

            string sql2 = "select classID from TeacherMessage where TeacherAccount='" + Form1.PublicValue.prtaccount + "'";
            OdbcCommand com2 = new OdbcCommand(sql2, con2);
            string classID = Convert.ToString(com2.ExecuteScalar());


            string sql1 = "select * from problem where date='" + comboBox1.Text + "' and classID= '"+classID + "'";
            OdbcCommand com1 = new OdbcCommand(sql1, con1);
            double cnt = 0;
            OdbcDataReader sdr1 = com1.ExecuteReader();
            while (sdr1.Read())
            {
                cnt+=1;
            }
            string sql3=" select * from childrenmessage where classID = "+classID;

            OdbcCommand com3 = new OdbcCommand(sql3, con3);
            double cnt2 = 0;
            OdbcDataReader sdr2 = com3.ExecuteReader();
            while (sdr2.Read())
            {
                cnt2+=1;
            }
            double re = cnt / cnt2;
            textBox1.Text = re.ToString() + "道/人";
        }
    }
}
